package com.app.TCES.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.app.TCES.domain.Course;
import com.app.TCES.service.A_CourseService;

@Controller
public class A_CourseController {

	Logger log = LogManager.getLogger(A_CourseController.class);

	@Autowired
	A_CourseService a_CourseService;

	// 查询所有课程信息
	@ResponseBody
	@RequestMapping("/selectCourse")
	public Map<String, Object> selectCourses() {
		log.debug("A_CourseController======>开始查询所有课程信息");

		List<Course> list = a_CourseService.selectCourses();

		log.debug("A_CourseController======>返回所有课程信息");

		Map<String, Object> map = new HashMap<String, Object>();

		map.put("tol", 1);
		map.put("message", "查询成功");
		map.put("list", list);
		map.put("status", 200);

		return map;

	}

	// 删除课程信息
	@ResponseBody
	@RequestMapping("/deleteCourse")
	public Map<String, String> deleteCourse(int courseId) {

		a_CourseService.deleteCourse(courseId);
		Map<String, String> map = new HashMap<String, String>();

		map.put("msg", "YES");
		return map;

	}

	// 添加(验证课程Id是否存在)
	@ResponseBody
	@RequestMapping("/selectCourseId")
	public Map<String , String > selectCourseId(int courseId) {
		log.debug("开始验证Id");
		String a = a_CourseService.selectCourseId(courseId);
		Map<String, String> map = new HashMap<String, String>();
		map.put("msg", a);
		return map;
	}

	// 添加(验证课程Name是否存在)
	@ResponseBody
	@RequestMapping("/selectCourseName")
	public Map<String , String > selectCourseName(String courseName) {
		String a = a_CourseService.selectCourseName(courseName);
		Map<String, String> map = new HashMap<String, String>();
		map.put("msg", a);
		return map;
	}

	//添加
	@ResponseBody
	@RequestMapping("/insertCourse")
	public  Map<String , String > insertcourse(int courseId,String courseName){
		log.debug("开始执行插入数据");
		
		String a = a_CourseService.insertCourse(courseId, courseName);
		
		log.debug("插入数据成功");
		Map<String, String> map = new HashMap<String, String>();
		map.put("msg", a);
		return map;
		
		
	}
	
	
}
